Skip to content

feat: add no-ai-colon-continuation rule with kuromojin morphological analysis #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 5, 2025

Conversation

azu
Copy link
Member

@azu azu commented Jul 5, 2025

概要

  • AIが英語構文を日本語に直訳したパターンを検出する新ルール no-ai-colon-continuation を実装
  • kuromojinによる形態素解析を使用して、名詞と述語を正確に判定
  • 自然な日本語表現(使い方:等の名詞+コロン)は許可し、不自然なパターン(実行します:等の述語+コロン)を検出
  • ASTベースの検出でParagraph+ブロック要素(CodeBlock、List、BlockQuote、Table)の組み合わせを正確に解析
  • ai-tech-writing-guidelineルールから重複するコロン検出処理を削除して競合を回避

no-ai-colon-continuation

コロンの直後にブロック要素が続く英語的なパターンを検出します。日本語として自然な表現を促進するルールです。

このルールは形態素解析(kuromojin)を使用して、コロンの前の文が述語(動詞・形容詞・助動詞)で終わっているかを判定します。「使用方法:」のような名詞で終わる表現は自然な日本語として許可され、「実行します:」のような述語で終わる表現のみを検出します。

検出される例

実行します:

```bash
command
```

説明します:

- 項目1
- 項目2

例えば:

- 具体的な例

より自然な日本語表現

実行方法は以下の通りです。

```bash
command
```

説明の内容は以下の通りです。

- 項目1
- 項目2

たとえば、次のような例があります。

- 具体的な例

例:

- 具体的な例

実装詳細

主要機能

  • 形態素解析: kuromojinを使用してコロン前のテキストが名詞または述語で終わるかを正確に判定
  • AST基盤の検出: MarkdownのAST構造を解析してParagraph+ブロック要素パターンを検出
  • 英語テキスト対応: 英語でのコロン使用は自然なため許可
  • StringSource統合: Markdown構文を除去してクリーンなテキスト解析を実現
  • 包括的オプション: 異なるブロック要素タイプに対する無効化フラグとallow パターンをサポート

検出パターン

  • 実行します: + CodeBlock/List/BlockQuote/Table → エラー(述語+コロン)
  • 説明します: + あらゆるブロック要素 → エラー(述語+コロン)
  • 例えば: + あらゆるブロック要素 → エラー(接続詞+コロン、機械的パターン)
  • 使い方: + あらゆるブロック要素 → OK(名詞+コロン)
  • API仕様: + あらゆるブロック要素 → OK(名詞+コロン)
  • 検出される例: + あらゆるブロック要素 → OK(受動形、名詞的)
  • 検出する例: + あらゆるブロック要素 → OK(連体形+名詞、名詞的)

関連Issue

Fixes #16

🤖 Generated with Claude Code

azu added 2 commits July 5, 2025 16:50
…analysis

- Implement new rule to detect English syntax patterns translated to Japanese
- Use kuromojin for accurate part-of-speech analysis to distinguish nouns from predicates
- Allow natural Japanese expressions like '使い方:' (noun + colon)
- Detect unnatural patterns like '実行します:' (predicate + colon)
- Support AST-based detection for Paragraph + block element combinations
- Remove duplicate colon detection from ai-tech-writing-guideline rule
- Add comprehensive test coverage for various patterns

Fixes #16
- Add support for both half-width (:) and full-width (:) colons
- Include conjunction detection (例えば: should be flagged)
- Port original test cases from ai-tech-writing-guideline
- Ensure proper colon character display in error messages
- All tests now passing with comprehensive pattern coverage
@azu azu added the Type: Feature New Feature label Jul 5, 2025
- Remove redundant colon index calculation
- Determine colon type once and reuse
- Remove unused colonIndex variable
- Keep clean and efficient implementation
@azu
Copy link
Member Author

azu commented Jul 5, 2025

PR #15 との関係について

PR #15 では、コロン + 箇条書きパターンの検出を無効化するオプションの追加を検討していましたが、今回の実装によりルール自体を分離したため、より柔軟な制御が可能になりました。

以前の課題

  • ai-tech-writing-guideline 内でコロンパターンを無効化するオプションが必要
  • 他の構造化ガイダンスと混在して制御が複雑

現在の解決策

新しい no-ai-colon-continuation ルールとして分離したことで、ルール自体を無効にできます。

{
  "rules": {
    "@textlint-ja/preset-ai-writing": {
      "no-ai-colon-continuation": false,
      "ai-tech-writing-guideline": true
    }
  }
}

または個別設定も可能です。

{
  "rules": {
    "@textlint-ja/preset-ai-writing": {
      "no-ai-colon-continuation": {
        "disableCodeBlock": true,
        "disableList": false
      }
    }
  }
}

Copy link
Member Author

@azu azu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

READMEに説明をついかする必要がある

@azu azu self-assigned this Jul 5, 2025
@azu azu mentioned this pull request Jul 5, 2025
9 tasks
@azu azu merged commit 2522ce8 into main Jul 5, 2025
4 checks passed
@azu azu deleted the feature/no-ai-colon-block-pattern branch July 5, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

新しいルール: コロン(:)とブロック要素の組み合わせを検出するルール
1 participant